import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"
import { getBizUrl } from '/@/utils/common/bizUrlUtils'
export interface RamResource {
  url: string
  apiAction: string
  actionType: string
  apiName: string
  apiSummary: string
}
export const pageApiResource = (params) => {
  const url = '/iam-service/apiResource/pageResource'
  return defHttp.get({ url, params })
}

export const listApiResource = (params) => {
  return defHttp.get<RamResource[]>({ url : '/iam-service/apiResource/listResource' , params })
}

export const saveOrUpdateApiResource = (params, isUpdate) => {
  const url = isUpdate ? "/iam-service/apiResource/updateResource" : "/iam-service/apiResource/saveResource"
  return defHttp.post({ url, params })
}

export const getApiResource = (params) => {
  return defHttp.get({ url: "/iam-service/apiResource/getResource", params })
}

export const syncApiResource = () => {
  const url = "/iam-service/apiResource/syncResource"
  return defHttp.post({ url, timeout: 20000000 })
}

export const deleteApiResource = (params, handleSuccess) => {
  const url = "/iam-service/apiResource/deleteResourceById"
  return defHttp.delete({ url , data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const batchDeleteApiResource = (params, handleSuccess) => {
  const url = "/iam-service/apiResource/deleteResourceByIds"
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}


export const listAllInstance = (params) => {
  return defHttp.get({ url: '/iam-service/resourceInstance/list', params })
}

export const listInstance = (params) => {
  return defHttp.get({url: '/iam-service/resourceInstance/list', params});
}

export const getInstance = (params) => {
  return defHttp.get({url: '/iam-service/system/resourceInstance/get', params});
}

export const pageInstance = (params) => {
  return defHttp.get({url: '/iam-service/system/resourceInstance/page', params});
}

export const saveOrUpdateInstance = (params, isUpdate) => {
  let url = '/iam-service/system/resourceInstance/' + (isUpdate ? 'update' : 'save');
  return defHttp.post({url: url, params});
}

export const deleteInstance = (params, handleSuccess) => {
  return defHttp.delete({url: '/iam-service/system/resourceInstance/delete', data: params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
